//
//  Schedule_Add_Task.m
//  EpointFrame5
//
//  Created by Pill Gong on 14-2-20.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "Schedule_Add_Task.h"
#import "ScheduleInfo.h"

@implementation Schedule_Add_Task

- (void)execute {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *ValidateData = [EpointBizTools getToken];
    NSString *url = self.getMobileOAWebserviceURL;
    NSString *wsNamespace = NSLocalizedString(@"Epoint_DNet_WS_NameSpace", @"");
    NSString *userguid = [userDefaults objectForKey:Epoint_User_UserGuid];
    NSString *Subject = [params objectForKey:@"Subject"];
    NSString *Location = [params objectForKey:@"Location"];
    NSString *Importance = [params objectForKey:@"Importance"];
    NSString *ActivityDescription = [params objectForKey:@"ActivityDescription"];
    NSString *FromDateTime = [params objectForKey:@"FromDateTime"];
    NSString *ToDateTime = [params objectForKey:@"ToDateTime"];
    NSString *ReceivePhone = [params objectForKey:@"ReceivePhone"];
    NSString *SendTime = [params objectForKey:@"SendTime"];
    NSString *IFNotice = [params objectForKey:@"IFNotice"];
    
    Subject =[EpointStringUtil filterXmlString:Subject];
    Location =[EpointStringUtil filterXmlString:Location];
    ActivityDescription =[EpointStringUtil filterXmlString:ActivityDescription];
    
    NSString *ParasXml = @"<![CDATA[<?xml version=\"1.0\" encoding=\"gb2312\"?><paras><UserGuid>%@</UserGuid><Subject>%@</Subject><Location>%@</Location><Importance>%@</Importance><ActivityDescription>%@</ActivityDescription><FromDateTime>%@</FromDateTime><ToDateTime>%@</ToDateTime><ReceivePhone>%@</ReceivePhone><SendTime>%@</SendTime><IFNotice>%@</IFNotice></paras>]]>";

    ParasXml = [NSString stringWithFormat:ParasXml,userguid,Subject,Location,Importance,ActivityDescription,FromDateTime,ToDateTime,ReceivePhone,SendTime,IFNotice];
    
    if (![self isNetWorkAvailable])
    {
        [self exeFailureWithMessage:FailToLoadNetWorkPleaseCheckTheSetting];
    }
    else
    {
        //请求接口
        EpointWebServiceUtil *ws = [[EpointWebServiceUtil alloc]initWithUrl:url namespace:wsNamespace method:@"Schedule_Add"];
        [ws addParameterForString:@"ValidateData" value:ValidateData];
        [ws addParameterForString:@"ParasXml" value:ParasXml];
        NSString *bs =  ws.start;
        
        NSMutableArray *result = [self validateXMLWS2:bs];
        NSString *msg = [result objectAtIndex:1];
        if ([[result objectAtIndex:0]isEqualToString:@"1"]) {
            [self sendDataRefreshUI:@[@"1", @"添加成功！"]];
        }
        else
        {
            [self exeFailureWithMessage:msg];
        }
    }
}

@end
